<% title "#{formatted_host} Repositories - Libraries.io" %>
<% description "Explore popular #{formatted_host} Repositories on Libraries.io" %>

<div class='row'>
  <div class='col-md-12'>
    <h1><i class="fa fa-<%= current_host_icon %>"></i> <%= @title %></h1>
  </div>
</div>
<hr>
<div class="row">
  <div class="col-md-8">
    <div class='row'>
      <% if @popular.any? %>
        <div class='col-sm-6'>
          <h4>
            Highest ranked <%= @title %>
          </h4>
          <%= render @popular %>
        </div>
      <% end %>
      <% if @forked.any? %>
        <div class='col-sm-6'>
          <h4>
            Most Forked <%= @title %>
          </h4>
          <%= render @forked %>
        </div>
      <% end %>
    </div>
    <hr>
    <div class='row'>
      <% if @created.any? %>
      <div class='col-sm-6'>
        <h4>
          New <%= @title %>
        </h4>
        <%= render @created %>
      </div>
      <% end %>
      <% if @updated.any? %>
      <div class='col-sm-6'>
        <h4>
          Recently Updated <%= @title %>
        </h4>
        <%= render @updated %>
      </div>
      <% end %>
    </div>
  </div>
  <div class="col-md-4">
    <div class='row'>
      <% if @languages.any? %>
        <div class='col-md-12 col-sm-4 facets'>
          <h4>Popular Languages</h4>
          <ul class='filter'>
            <% @languages.each do |language| %>
              <li class='<%= 'active' if language['key'].downcase == params[:language].try(:downcase) %>'>
                <% if language['key'].downcase == params[:language].try(:downcase) %>
                  <%= link_to format_language(language['key']), url_for(params.except(:host).merge(language: nil).permit!) %>
                <% else %>
                  <%= link_to format_language(language['key']), url_for(params.except(:host).merge(language: format_language(language['key'])).permit!) %>
                  <small><%= pluralize number_to_human(language['doc_count']), 'repos' %></small>
                <% end %>
              </li>
            <% end %>
            <% if @language && !@languages.map{|l| l[0].downcase }.include?(@language.name.downcase) %>
              <li class='active'>
                <%= link_to format_language(@language.name), url_for(params.except(:host).merge(language: nil).permit!) %>
              </li>
            <% end %>
          </ul>
        </div>
      <% end %>
      <% if current_host.blank? && @host_types.any? %>
        <div class='col-md-12 col-sm-4 facets'>
          <h4>Popular Hosts</h4>
          <ul class='filter'>
            <% @host_types.each do |host_type| %>
              <li class='<%= 'active' if host_type['key'].downcase == params[:host_type].try(:downcase) %>'>
                <% if host_type['key'].downcase == params[:host_type].try(:downcase) %>
                  <%= link_to host_type['key'], url_for(params.except(:host).merge(host_type: nil).permit!) %>
                <% else %>
                  <%= link_to host_type['key'], url_for(params.except(:host).merge(host_type: host_type['key'].downcase).permit!) %>
                  <small><%= pluralize number_to_human(host_type['doc_count']), 'repos' %></small>
                <% end %>
              </li>
            <% end %>
            <% if @language && !@languages.map{|l| l[0].downcase }.include?(@language.name.downcase) %>
              <li class='active'>
                <%= link_to format_language(@language.name), url_for(params.except(:host).merge(language: nil).permit!) %>
              </li>
            <% end %>
          </ul>
        </div>
      <% end %>
      <% if @licenses.any? %>
        <div class='col-md-12 col-sm-4 facets'>
          <h4>Popular Licenses</h4>
          <ul class='filter'>
            <% @licenses.each do |license| %>
              <li class='<%= 'active' if license['key'].downcase == params[:license].try(:downcase) %>'>
                <% if license['key'].downcase == params[:license].try(:downcase) %>
                  <%= link_to format_license(license['key']), url_for(params.except(:host).merge(license: nil).permit!) %>
                <% else %>
                <%= link_to format_license(license['key']), url_for(params.except(:host).merge(license: format_license(license['key'])).permit!) %>
                <small><%= pluralize number_to_human(license['doc_count']), 'repos' %></small>
                <% end %>
              </li>
            <% end %>
            <% if @license && !@licenses.map{|l| l['key'].downcase }.include?(@license.id.downcase) %>
              <li class='active'>
                <%= link_to format_license(@license.id), url_for(params.except(:host).merge(license: nil).permit!) %>
              </li>
            <% end %>
          </ul>
        </div>
      <% end %>
      <% if @keywords.any? %>
        <div class='col-md-12 col-sm-4 facets'>
          <h4>Popular Keywords</h4>
          <ul class='filter'>
            <% @keywords.each do |keyword| %>
              <li class='<%= 'active' if keyword['key'].downcase == params[:keywords].try(:downcase) %>'>
                <% if keyword['key'].downcase == params[:keywords].try(:downcase) %>
                  <%= link_to keyword['key'], url_for(params.except(:host).merge(keywords: nil).permit!) %>
                <% else %>
                  <%= link_to keyword['key'], url_for(params.except(:host).merge(keywords: keyword['key']).permit!) %>
                  <small><%= pluralize number_to_human(keyword['doc_count']), 'repos' %></small>
                <% end %>
              </li>
            <% end %>
            <% if @keyword && !@keyword.map{|l| l['key'].downcase }.include?(@keyword.downcase) %>
              <li class='active'>
                <%= link_to @keyword, url_for(params.except(:host).merge(keywords: nil).permit!) %>
              </li>
            <% end %>
          </ul>
        </div>
      <% end %>
    </div>
  </div>
</div>
